<template>
  {{ num }}
  <button @click="open = true">点击弹出弹框</button>
  <teleport to="body">
    <div class="wrap" v-if="open">
      <div class="box">
        <button @click="open = false">关闭</button>
        <input type="text" v-model="content" name="" id="" />
        <p>
          <button @click="content = null">清空</button
          ><button @click.prevent="Ensure">确认</button>
        </p>
      </div>
    </div>
  </teleport>
</template>
<script>
export default {
  methods: {
    Ensure() {
      if (this.content) {
        this.num = this.content;
        this.content = null;
      }
    },
  },
  data() {
    return {
      open: false,
      num: 0,
      content: null,
    };
  },
};
</script>
<style scoped>
* {
  user-select: none;
}
.wrap {
  position: fixed;
  left: 0;
  top: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  justify-content: center;
  align-items: center;

  width: 100%;
  height: 100%;
}
.box {
  width: 200px;
  background: white;
  border-radius: 10px;
  padding: 20px;

  display: flex;
  flex-direction: column;
  align-items: center;
}
.box > button {
  align-self: flex-end;
  margin: 15px;
}
.box > p {
  width: 200px;
  margin: 30px 0 0 0;
  display: flex;
  justify-content: space-evenly;
}
</style>

